function init () {
    $('input').daterangepicker({
        dateFormat: 'dd-mm-yy'
    });
} // init

function getReport (page) {
    var date     = Ext.fly('dateRange').getValue();
    var stockist = Ext.fly('stockistId').getValue();

    date = (date == 'Choose a Date') ? '' : date;

    if (typeof(page) == 'undefined') {
        var page = 1;
    }

    var transId = Ext.Ajax.request({
        url: _webroot+'/admin/sales/top_bv_purchase_report',
        method: 'POST',
        params: 'date='+date+'&stockist='+stockist+'&page='+page,
        success: function(response, opts) {
            Ext.fly('report-list-body').update(response.responseText);
        },
        failure: function(response, opts) {
            message('server-side failure with status code '+response.status);
        },
        callback: function() {
            Ext.fly('report-list-status').ghost('b', { useDisplay:true });
        }
    });

    if (Ext.Ajax.isLoading(transId)) {
        Ext.fly('report-list-status').fadeIn().update('Loading..')
    }
} // getReport

function message (msg, focus) {
    alert(msg);

    if (typeof focus != 'undefined') {
        Ext.fly(focus).focus();
    }
} // message